package cn.ilikes.tools.hbase.jpa.persistences.transactions;

import javax.persistence.EntityTransaction;

import org.slf4j.Logger;

import cn.ilikes.tools.hbase.jpa.JPAHBaseNoSupportException;
import cn.ilikes.tools.hbase.jpa.persistences.context.AbstractContext;
import cn.ilikes.tools.logs.Loggerfactory;

public class JPAHBaseTransaction implements EntityTransaction {

	private static Logger logger = Loggerfactory.instance(JPAHBaseTransaction.class);

	private AbstractContext context;

	public JPAHBaseTransaction(AbstractContext context) {
		super();
		this.context = context;
	}

	@Override
	public void begin() {
		if (Loggerfactory.isdebug(logger))
			Loggerfactory.info(logger, "JPA HBase transaction    begin   ");
		this.context.init();
	}

	@Override
	public void commit() {
		if (Loggerfactory.isdebug(logger))
			Loggerfactory.info(logger, "JPA HBase transaction    commit   ");
		this.context.commit();

	}

	@Override
	public boolean getRollbackOnly() {
		Loggerfactory.info(logger, "JPAHBaseTransaction   getRollbackOnly    this not work  ,default  true ! ");
		return false;
		//		throw new JPAHBaseNoSupportException("this not work ");
	}

	@Override
	public boolean isActive() {

		Loggerfactory.info(logger, "JPAHBaseTransaction   isActive    this not work  ,default  true ! ");
		return true;
		//throw new JPAHBaseNoSupportException("this not work ");
	}

	@Override
	public void rollback() {
		if (Loggerfactory.isdebug(logger))
			Loggerfactory.info(logger, "JPA HBase transaction    commit   ");
		this.context.rollback();

	}

	@Override
	public void setRollbackOnly() {
		throw new JPAHBaseNoSupportException("this not work ");

	}

}
